In [1]:
!pip3 install Flask
In [8]:
from flask import Flask
app = Flask(__name__)
@app.route("/blah")
def hello():
return "Hello, world!"
@app.route("/hello")
def fun_response_yay():
return "you went to the path /Hello, congratulations!"
@app.route("/")
def index_resource():
return "welcomt to example server."
app.run()
In [9]:
localhost = 127.0.0.1
In [10]:
''.join(reversed("mammoth"))
Out[10]:
In [11]:
''.join(list(reversed("slipup")))
Out[11]:
In [14]:
from flask import Flask,request
app = Flask(__name__)
@app.route("/reverse")
def reverser():
word = request.args.get('word',None)
if word:
word_in_reverse = ''.join(reversed(word))
return word_in_reverse
else:
return("you did not use the API correctly")
app.run()
In [17]:
x = {'orange':6, 'apples':4, 'durians':2}
In [18]:
if "passionfruit" in x:
print(x['passionfruit'])
In [19]:
x.get('passionfruit',0)
Out[19]:
In [20]:
x.get('apples',0)
Out[20]:
In [21]:
import random
In [23]:
random.randrange(1, 21)
Out[23]:
In [24]:
random.uniform(0,1)
Out[24]:
In [25]:
random.choice(['hello','hi','howdy','hey','sup'])
Out[25]:
In [ ]:
from flask import Flask,request
app = Flask(__name__)
greets = ['hello','hi','howdy','hey','sup']
punc = ['!','!!','?',".","....."]
@app.route("/greeting")
def greet_generator():
thing = request.args['to_greet']
greeting = random.choice(greets) + " " + thing + random.choice(punc)
return greeting
app.run()
In [ ]: